// pages/distribution/distribution.js
var model=require('../distribution/model/DistributionModel.js')
import SystemInfoUtil from '../../utils/SystemInfoUtil.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentPageIndex:1,
    isIOS: false,
    distributionList:[]
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _isIOS = SystemInfoUtil.platform == SystemInfoUtil.IOS
    var teacherId = ''
    if (options.teacherId) {
      teacherId = options.teacherId
    }
    this.setData({
      isIOS: _isIOS,
      teacherId:teacherId
    })
    console.log("接受到的"+options.teacherId)
    
    this.loadDistributionList(this.data.currentPageIndex, teacherId)
  },
  loadDistributionList(pageIndex,teacherId){
    var that=this
    model.getDistributionList(pageIndex, "awardMoney1",teacherId,function(list){
      if(list!=null&&list.length>0){
        that.setData({
          distributionList: that.data.distributionList.concat(list),
          currentPageIndex:pageIndex
        })
      }
    })
  },
  onItemClick:function(event){
    var position = event.currentTarget.dataset.position
    var obj = this.data.distributionList[position];
    if(obj){
      var _url = '../distribution-detail/detail?obj=' + JSON.stringify(obj)
      wx.navigateTo({
        url: _url,
      })
    }
  },
  //规则
  aboutRule:function(event){
    wx.navigateTo({
      url: '../distribution-rule/rule',
    })
  },
  //赏金
  myAward:function(event){
    wx.navigateTo({
      url: '../distribution-award/award',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    var teacherId = ''
    if (this.data.teacherId) {
      teacherId = this.data.teacherId
    }
    console.log("data"+this.data)
    console.log(teacherId)
    
    this.loadDistributionList(this.data.currentPageIndex+1,teacherId)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})